package com.patterns.factory.LazyFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Xiao Yiyun on 2017/4/14.
 */
public class ProductFactory {

    private static final Map<String, Prodect> prMap = new HashMap();

    public static synchronized Prodect create(String str) throws Exception {

        Prodect prodect;

        if (prMap.containsKey(str)) {
            prodect = prMap.get(str);
            System.out.println("map get");
        } else {
            if (str.equals("Prodect1")) {
                prodect = P1Factory.create();
                System.out.println("p1 create");
            } else {
                prodect = P2Factory.create();
                System.out.println("p2 create");
            }
            prMap.put(str, prodect);
        }
        return prodect;
    }
}
